﻿using System;

namespace _2
{
    // 定义员工类
    public class Employee
    {
        // 私有成员变量（字段）
        private int id;          // 员工ID
        private string name;     // 员工姓名
        private int age;         // 年龄
        private string department; // 部门
        private double salary;   // 工资
        private string position; // 职位

        // 无参构造函数
        public Employee()
        {
            id = 0;
            name = "未知";
            age = 0;
            department = "未分配";
            salary = 0;
            position = "未定";
        }

        // 带参构造函数
        public Employee(int id, string name, int age, string department, double salary, string position)
        {
            this.id = id;
            this.name = name;
            this.age = age;
            this.department = department;
            this.salary = salary;
            this.position = position;
        }

        // Getter和Setter方法
        public int GetId()
        {
            return id;
        }

        public void SetId(int id)
        {
            if (id > 0)
                this.id = id;
            else
                Console.WriteLine("ID必须大于0");
        }

        public string GetName()
        {
            return name;
        }

        public void SetName(string name)
        {
            if (!string.IsNullOrEmpty(name))//判断NAME为空
                this.name = name;
            else
                Console.WriteLine("姓名不能为空");
        }

        public int GetAge()
        {
            return age;
        }

        public void SetAge(int age)
        {
            if (age >= 18 && age <= 65)
                this.age = age;
            else
                Console.WriteLine("年龄必须在18-65之间");
        }

        public string GetDepartment()
        {
            return department;
        }

        public void SetDepartment(string department)
        {
            if (!string.IsNullOrEmpty(department))
                this.department = department;
            else
                Console.WriteLine("部门不能为空");
        }

        public double GetSalary()
        {
            return salary;
        }

        public void SetSalary(double salary)
        {
            if (salary >= 0)
                this.salary = salary;
            else
                Console.WriteLine("工资不能为负数");
        }

        public string GetPosition()
        {
            return position;
        }

        public void SetPosition(string position)
        {
            if (!string.IsNullOrEmpty(position))
                this.position = position;
            else
                Console.WriteLine("职位不能为空");
        }

        // 显示所有成员信息的方法
        public void DisplayInfo()
        {
            Console.WriteLine("=== 员工信息 ===");
            Console.WriteLine($"员工ID: {id}");
            Console.WriteLine($"姓 名: {name}");
            Console.WriteLine($"年 龄: {age}");
            Console.WriteLine($"部 门: {department}");
            Console.WriteLine($"职 位: {position}");
            Console.WriteLine($"工 资: {salary:C}");
            Console.WriteLine("================");
        }

        // 计算年薪的方法（额外功能）
        public double CalculateAnnualSalary()
        {
            return salary * 12;
        }

        // 员工评级方法（额外功能）
        public string GetEmployeeLevel()
        {
            if (salary >= 15000) return "高级";
            else if (salary >= 8000) return "中级";
            else return "初级";
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("=== 员工管理系统测试 ===");

            // 测试1：使用无参构造函数创建对象
            Console.WriteLine("\n1. 使用无参构造函数创建员工：");
            Employee emp1 = new Employee();
            emp1.DisplayInfo();

            // 测试2：使用全参构造函数创建对象
            Console.WriteLine("\n2. 使用全参构造函数创建员工：");
            Employee emp2 = new Employee(1001, "张三", 28, "技术部", 12000, "软件工程师");
            emp2.DisplayInfo();
            Console.WriteLine($"年薪: {emp2.CalculateAnnualSalary():C}");
            Console.WriteLine($"员工等级: {emp2.GetEmployeeLevel()}");

          
            // 测试4：使用Setter方法修改属性
            Console.WriteLine("\n4. 使用Setter方法修改员工信息：");
            emp2.SetDepartment("市场部");
            emp2.SetPosition("市场专员");
            emp2.SetSalary(8500);
            emp2.DisplayInfo();
            Console.WriteLine($"年薪: {emp2.CalculateAnnualSalary():C}");
            Console.WriteLine($"员工等级: {emp2.GetEmployeeLevel()}");

            // 测试5：测试数据验证
            Console.WriteLine("\n5. 测试数据验证：");
            Employee emp4 = new Employee();
            emp4.SetId(-1);          // 无效ID
            emp4.SetAge(16);         // 无效年龄
            emp4.SetSalary(-1000);   // 无效工资
            emp4.SetName("");        // 无效姓名

            // 测试6：使用Getter方法获取信息
            Console.WriteLine("\n6. 使用Getter方法获取信息：");
            Console.WriteLine($"员工{emp2.GetName()}的ID是：{emp2.GetId()}");
            Console.WriteLine($"在{emp2.GetDepartment()}部门担任{emp2.GetPosition()}职位");

            // 测试7：创建员工数组
            Console.WriteLine("\n7. 员工列表：");
            Employee[] employees = {
                new Employee(1003, "王五", 32, "财务部", 9500, "会计"),
                new Employee(1004, "赵六", 29, "人事部", 11000, "HR经理"),
                new Employee(1005, "钱七", 35, "销售部", 18000, "销售总监")
            };

            foreach (var emp in employees)//循环遍历员工信息
            {
                emp.DisplayInfo();
                Console.WriteLine();
            }

           
        }
    }
}
